﻿var startAddress;
var endAddress;
var directionManager;
var map
var queryStringManager;

function load() {
  if (GBrowserIsCompatible()) 
  {
    map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(37.4419, -122.1419), 13);
    map.setUIToDefault();

    queryString = window.location.search.substring(1)
    directionManager = new GDirections(map, document.getElementById("route"));
    queryStringManager = new Querystring(document.location.href);
    
    startAddress = queryStringManager.get("saddr","");
    endAddress = queryStringManager.get("daddr","");
    setDirections(startAddress, endAddress, "en_US");

    var gx = new GGeoXml("http://www.dev-poleposition.com/Deploy/WebSite2.1/kmlmap.aspx?" + queryString);
    map.addOverlay(gx);
  }
}

  
function setDirections(fromAddress, toAddress, locale) 
{
  directionManager.load("from: " + fromAddress + " to: " + toAddress,
            {locale: locale, travelMode:G_TRAVEL_MODE_DRIVING,avoidHighways: true});
  //document.getElementById('distanceWalked').innerHTML=gdir.GDirections.getDistance().html;
}

